package Controller

import (
	"github.com/gin-gonic/gin"
	"github.com/jinzhu/copier"
	"log"
	"web_back_go/DAO/gorm"
	"web_back_go/DAO/gorm/GormModel"
	"web_back_go/Response"
)

type indexImagesRes struct {
	ImgUrl     string `json:"imgUrl"`
	Seq        int    `json:"seq"`
	UploadTime string `json:"uploadTime"`
	Type       int    `json:"type"`
	Relation   int    `json:"relation"`
}

func GetIndexImagesController(c *gin.Context) {
	var db = gorm.Db
	var indexImages []GormModel.TzIndexImg

	result := db.Table("tz_index_img").
		Where("status = ?", 1).
		Order("Seq DESC").
		Find(&indexImages)
	if result.Error != nil {
		log.Println(result.Error)
		c.JSON(200, Response.ResponseBody{
			Code:    "A00001",
			Msg:     "服务器异常",
			Data:    nil,
			Version: "1.0.0",
		})
		return
	}
	var indexImagesRes []indexImagesRes
	_ = copier.Copy(&indexImagesRes, &indexImages)
	c.JSON(200, Response.ResponseBody{
		Code:    "00000",
		Msg:     nil,
		Data:    &indexImagesRes,
		Version: "1.0.0",
	})
}
